﻿#ifndef FXPROTOCOL_H
#define FXPROTOCOL_H

#include <QObject>
#include <QDebug>
#include <QTimer>
#include <QTime>
#include "SerialCom.h"
#include "PLCClientBase.h"

class FXProtocol : public PLCClientBase
{
    Q_OBJECT
public:
    explicit FXProtocol(const QString& name = "", QObject *parent = nullptr);
    virtual ~FXProtocol();
signals:

public:
    void onStateChanged(ComState state);
protected:
    virtual void processData(const PLCRequestData& requestData){}
    //    virtual void reconnect() override{}
    void initCom() override;
    void sendReadData(const PLCRequestData& data) override;
    void sendWriteData(const PLCRequestData& data) override;
private:
    QString getReadHoldRegisterCommand(int startAddr, int length);
    QString getReadCoilsRegisterCommand(int startAddr, int length);
    QString getWriteHoldRegisterCommand(int startAddr, int length, QList<ModbusValue> vData);
    QString getWriteCoilsRegisterCommand(int startAddr, int length, QList<ModbusValue> vData);
    //    inline QList<qint16> transToListInt(const QByteArray &buf);
    //    inline QList<float> transToListFloat(const QByteArray &buf);
    void onReceiveData(const QByteArray& data);
    QString computeSum(QString linkstring);
    SerialCom *mSerialClient;

    QString addrNumStr(int startAddr, int num);
};

#endif // FXPROTOCOL_H
